package jtk.project4.fleet.screen.meterReplacements;



import java.awt.FlowLayout;

import jtk.project4.fleet.domain.Odometer;
import jtk.project4.fleet.field.MeterReplacementsButtonField;
import jtk.project4.fleet.field.MeterReplacementsField;

import nl.coderight.jazz.action.Action;
import nl.coderight.jazz.form.FormView;
import nl.coderight.jazz.form.control.GroupControl;
import nl.coderight.jazz.form.field.TableField;
import nl.coderight.jazz.form.field.button.PushButton;
import nl.coderight.jazz.form.field.table.TableFieldColumn;
import nl.coderight.jazz.form.FormField;

public class MeterReplacementsView extends FormView{
	
	private PushButton helpButton;
	private PushButton closeButton;
	private Action helpAction;
	private Action closeAction;
	private TableField<Odometer> field1;
	
	/*public void handleEvent(MeterReplacementsEvent evt) {
		switch (evt.getType()) {
		case CLOSE:
			close();
			break;
			
		case SUBMIT:
			// check for validation errors
			List<ValidationError> errors = validate();
			if (!errors.isEmpty()) {
				// there are validation errors so do not submit...
				errors.get(0).getField().focus();
				break;
			} else {
				// submit form and close view
				submit();
				close();
				// fall-through!
			}
			
		default:
			// propagate event to controller
			propagateEvent(evt);
			break;
		}
	}*/
	
	@Override
	/*public void close() {
		// check if form is changed, if true show dialog
		if (isChanged()) {
			OptionDialog dialog = new OptionDialog(this);
			dialog.setMessageType(MessageType.QUESTION);
			dialog.setTitle("dialog.discard.title");
			dialog.setMessage("dialog.discard.message");
			//cfdialog.setOptionType(OptionType.YESlk_NO);
			dialog.setOptions("button.yes", "button.no", "");
			dialog.show();
			if (dialog.getReturnOptionType() == ReturnOptionType.NO) {
				focus();
				return;
			}
		}
		super.close();
	}*/
	
	
	
	protected void init() {
		createFields();
		createLayout();		
	}	
	
		
	private void createFields(){
		
	    field1 = new TableField<Odometer>("odometers","odometer");
	  	field1.addColumn("Unit","odId");
		field1.addColumn("Year","createDate");
		field1.addColumn("Current Reading","currentMeter");
		field1.addColumn("Replacement Reading","replacementMeter");
		field1.addColumn("Description","desc");
		helpButton = new PushButton("Help");
		closeButton = new PushButton("closeAction");
		
	}
	
	private void createLayout() {
		addField(createForm());
		}
	
	
	private GroupControl createForm() {
		GroupControl form = new GroupControl();
		form.addField(field1,NORTH);
		form.addField(new MeterReplacementsButtonField(" "), CENTER);
		form.addField(createButtons(), SOUTH);		
		return form;
	}
	
	private GroupControl createButtons() {
		GroupControl buttons = new GroupControl();
		buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
		buttons.addField(helpButton);
		buttons.addField(closeButton);
		return buttons;
	}
	
	

}
